package com.weixing.mall.provider.controller.common;

import com.weixing.mall.base.enums.SysCfgCodeEnum;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoNeedAccess;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.domain.Config;
import com.weixing.mall.provider.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统开关通用接口
 * @author siashan
 * @since 1.0
 */
@RestController
@RequestMapping("/cfg/common")
public class SysConfigCommonController extends BaseController {
    @Autowired
    private IConfigService sysConfigService;


    /**
     * 校验是否开启会员绑定代理商功能-开关
     *
     * @apiNote 1开启 ，0 关闭
     * @return 结果
     */
    @GetMapping("checkRegistAgentBind")
    @NoNeedAccess
    public Result<Integer> checkRegistAgentBind() {
        Config config = sysConfigService.selectByCfgCode(SysCfgCodeEnum.MEMBER_BIND_AGENT.getCode());
        return ResultUtil.successData(config.getCfgValue());
    }

    /**
     * 校验是否开启订单绑定代理商功能-开关
     * @apiNote 1开启 ，0 关闭
     * @return 结果
     */
    @GetMapping("checkOrderAgentBind")
    @NoNeedAccess
    public Result<Integer> checkOrderAgentBind() {
        Config config = sysConfigService.selectByCfgCode(SysCfgCodeEnum.ORDER_BIND_AGENT.getCode());
        return ResultUtil.successData(config.getCfgValue());
    }

    /**
     * 校验是否开启买家秀上传功能-开关
     *
     * @apiNote 1开启 ，0 关闭
     * @return 结果
     */
    @GetMapping("checkBuyerShow")
    @NoNeedAccess
    public Result<Integer> checkBuyerShow() {
        Config config = sysConfigService.selectByCfgCode(SysCfgCodeEnum.BUYER_SHOW_CFG.getCode());
        return ResultUtil.successData(config.getCfgValue());
    }


    /**
     * 校验是否开启代理商订单认领功能-开关
     *
     * @apiNote 1开启 ，0 关闭
     * @return 结果
     */
    @GetMapping("checkAgentOrderCliam")
    @NoNeedAccess
    public Result<Integer> checkAgentOrderCliam() {
        Config config = sysConfigService.selectByCfgCode(SysCfgCodeEnum.AGENT_ORDER_CLAIM.getCode());
        return ResultUtil.successData(config.getCfgValue());
    }


    /**
     * 校验是否开启代理商提现功能-开关
     *
     * @apiNote 1开启 ，0 关闭
     * @return 结果
     */
    @GetMapping("checkAgentWithd")
    @NoNeedAccess
    public Result<Integer> checkAgentWithd() {
        Config config = sysConfigService.selectByCfgCode(SysCfgCodeEnum.AGENT_WITHDROW_CFG.getCode());
        return ResultUtil.successData(config.getCfgValue());
    }


    /**
     * 商品分享功能是否开启-开关
     *
     * @apiNote 1开启 ，0 关闭
     * @return 结果
     */
    @GetMapping("checkShare")
    @NoNeedAccess
    public Result<Integer> checkShare() {
        Config config = sysConfigService.selectByCfgCode(SysCfgCodeEnum.SHARE.getCode());
        return ResultUtil.successData(config.getCfgValue());
    }

    /**
     * 是否允许取消订单-开关
     *
     * @apiNote 1开启 ，0 关闭
     * @return 结果
     */
    @GetMapping("checkOrderCancel")
    @NoNeedAccess
    public Result<Integer> checkOrderCancel() {
        Config config = sysConfigService.selectByCfgCode(SysCfgCodeEnum.ORDER_CANCEL.getCode());
        return ResultUtil.successData(config.getCfgValue());
    }

    /**
     * 积分-开关
     * @apiNote 1开启 ，0 关闭
     * @return 结果
     */
    @GetMapping("checkPoint")
    @NoNeedAccess
    public Result<Integer> checkPoint() {
        Config config = sysConfigService.selectByCfgCode(SysCfgCodeEnum.MEM_POINT.getCode());
        return ResultUtil.successData(config.getCfgValue());
    }

}
